/**
 * @Author：ming
 * @Date：2023/9/28 2:47 PM
 * @Filename：Lc80
 */

/**
 * @author ming
 */
public class Lc80 {
    public int removeDuplicates(int[] nums) {
        int len = nums.length;
        int count = len;
        int q = 1;
        int p = 0;
        while (q < len) {
            if(nums[p]==nums[q]){
                if(q<len-1){
                    if(nums[q]==nums[q+1]){
                        count--;
                        q++;
                    }else {
                        p++;
                        nums[p]=nums[q];
                        q++;
                    }
                }else {
                    p++;
                    nums[p]=nums[q];
                    q++;
                }

            }else {
                p++;
                nums[p]=nums[q];
                q++;

            }
        }

        return count;
    }
}
